cc.Class({
    extends: cc.Component,

    properties: {
        index: 0,
        prefabs: [cc.Prefab],

        _prefabNode: cc.Node,
    },
    editor: {
        menu: 'ExtendUI/LoadLinkPrefab'
    },

    start: function() {
        this.newPrefab();
    },

    newPrefab: function() {
        var prefab = this.prefabs[this.index];
        if (prefab) {
            this._prefabNode = prefab.newTo(this.node);
        }
    },
    removePrefab: function() {
        this._prefabNode && this._prefabNode.destroy();
    },
    setIndex: function(index) {
        this.removePrefab();
        this.index = index;
        this.newPrefab();
    },
});
